package com.zhhtech.zhh.ui.base

import android.view.View
import androidx.viewbinding.ViewBinding
import com.zhhtech.zhh.ui.listener.OnCheckBean

abstract class BaseSignCheckAdapter<VB : ViewBinding, B : OnCheckBean> : BaseRecyclerAdapter<VB, B>() {

    fun getCheck(): B {
        for (item in datas) {
            if (item.check) {
                return item
            }
        }
        return getItem(0)
    }

    // 单选
    override fun subOnClickAdapter(v: View, position: Int) {
        datas.forEachIndexed { index, checkBean ->
            if (position != index && checkBean.check) {
                checkBean.check = false
                notifyItemChanged(index)
            }
        }
        val item = getItem(position)
        if (!item.check) {
            item.check = true
            notifyItemChanged(position)
        }
    }
}